﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace luck.Models
{
    public class luckCompanyRepository 
    {
        private luckDataContext db = new luckDataContext();
        /* Ham lay danh sach cac company
        * @Param:
        * @Return:
        */
        public IQueryable<luckCompany> FindAllCompanys()
        {
            return from company in db.luckCompanies
                   orderby company.DateCreated descending
                   select company;
        }
        /* Tim kiem gia tri name ....
		* @Param:
		* @Return:
		*/
        public IQueryable<luckCompany> SearchCompanys(string key)
        {
            return from company in db.luckCompanies 
                   where company.CompanyName.Contains(key)
                   orderby company.DateCreated descending
                   select company;
        }
        /* Them company
		* @Param:luckCompany luckcompany
		* @Return:
		*/
        public void Add(luckCompany luckcompany)
        {
            db.luckCompanies.InsertOnSubmit(luckcompany);
        }
        /* Hàm xóa ....
        * @Param:luckCompany luckcompany
        * @Return:
        */
        public void Delete(luckCompany luckcompany)
        {
            db.luckCompanies.DeleteOnSubmit(luckcompany);
        }
        /* Lay company theo id ....
        * @Param:int id
        * @Return:
        */
        public luckCompany GetLuckCompany(int id)
        {
            return db.luckCompanies.SingleOrDefault(l => l.ID == id); 
        }
        //
        // Persistence 
        public void Save()
        {
            db.SubmitChanges();
        }
    }
}